<template>
  <a-popover
    v-model="visible"
    trigger="click"
    placement="bottomRight"
    overlayClassName="header-notice-wrapper"
    :getPopupContainer="() => $refs.noticeRef.parentElement"
    :autoAdjustOverflow="true"
    :arrowPointAtCenter="true"
    :overlayStyle="{ width: '300px', top: '50px' }"
  >
    <template slot="content">
      <a-spin :spinning="loading">
        <!-- <a-tabs> -->
          <!-- <a-tab-pane tab="通知" key="1"> -->
            <a-list  :data-source="listData">
             <div
                slot="loadMore"
                :style="{ textAlign: 'center', marginTop: '15px', height: '30px', lineHeight: '30px' }"
              >
                <!-- <a-spin v-if="loadingMore" /> -->
                <!-- <a-button v-if="unreadNotice > 0" @click="onLoadMore"> -->
                  <a-button @click="onLoadMore">
                查看更多...
                </a-button>
            </div>
            <a-list-item slot="renderItem" slot-scope="item">
                <a-list-item-meta  :description="item.sendTime">
                    <a style="font-size:14px" slot="title" @click="readNotice(item)">{{ item.title }} </a>
                       <a-avatar style="background-color: white" slot="avatar" src="https://gw.alipayobjects.com/zos/rmsportal/ThXAXghbEsBCCSDihZxY.png"/>
                  <!-- <a-avatar style="background-color: white" slot="avatar" :src="require('../../../assets/new-message.png')" /> -->
                </a-list-item-meta>
            </a-list-item>
         
            </a-list>
          <!-- </a-tab-pane> -->
          <!-- <a-tab-pane tab="文章" key="2">
            <a-list>
              <a-list-item>
                <a-list-item-meta title="你收到了 14 份新周报" description="一年前">
                  <a-avatar style="background-color: white" slot="avatar" src="https://gw.alipayobjects.com/zos/rmsportal/ThXAXghbEsBCCSDihZxY.png"/>
                </a-list-item-meta>
              </a-list-item>
              <a-list-item>
                <a-list-item-meta title="你推荐的 曲妮妮 已通过第三轮面试" description="一年前">
                  <a-avatar style="background-color: white" slot="avatar" src="https://gw.alipayobjects.com/zos/rmsportal/OKJXDXrmkNshAMvwtvhu.png"/>
                </a-list-item-meta>
              </a-list-item>
              <a-list-item>
                <a-list-item-meta title="这种模板可以区分多种通知类型" description="一年前">
                  <a-avatar style="background-color: white" slot="avatar" src="https://gw.alipayobjects.com/zos/rmsportal/kISTdvpyTAhtGxpovNWd.png"/>
                </a-list-item-meta>
              </a-list-item>
            </a-list>
          </a-tab-pane> -->
        <!-- </a-tabs> -->
      </a-spin>
    </template>
    <span @click="fetchNotice" class="header-notice" ref="noticeRef" style="padding: 0 18px">
      <a-badge :count="unreadNotice">
        <a-icon style="font-size: 16px; padding: 4px" type="bell" />
      </a-badge>
    </span>
  </a-popover>
</template>

<script>
import { mapActions, mapGetters } from 'vuex'
export default {
  name: 'HeaderNotice',
  data () {
    return {
      loading: false,
      visible: false,
      // 查询参数
      queryParam: {},
      //  loadingMore: false,
      listData:[],
      unreadNotice: 0,
    }
  },
  created () {
    this.getNoticeList();
  },
  methods: {
    ...mapActions(['GetUserNotice']),
    fetchNotice () {
      if (!this.visible) {
        this.loading = true
        setTimeout(() => {
          this.loading = false
        }, 100)
      } else {
        this.loading = false
      }
      this.visible = !this.visible
    },
     getNoticeList(){
          this.queryParam.pageNo = 1;
          this.queryParam.pageSize = 5;
          this.queryParam.isRead = false;
          this.GetUserNotice(this.queryParam).then((data) => {
               if (data) {
                this.listData = data.rows;
                this.unreadNotice = data.totalQuantity;
            }
            })
      },
      readNotice(detail){
        this.$router.push({name:'NoticeMessage', params:detail});
        this.timer = setTimeout(() => {
                    this.getNoticeList();
                  }, 1000)
        this.visible = false;
      },
      onLoadMore() {
        this.$router.push({name:'NoticeMessage'});
        this.visible = false;
      },
  },
  
}
</script>

<style lang="css">
  .header-notice-wrapper {
    top: 50px !important;
  }
</style>
<style lang="less" scoped>
  .header-notice{
    display: inline-block;
    transition: all 0.3s;

    span {
      vertical-align: initial;
    }
  }
</style>
